{extends file="../base.html"}
{block name=function}

{/block}
{block name=base}
{if powertree()}
{function tree level=1}
{foreach $data as $self_id=>$children}
<div class="menu_level menu_level_{$level} {if !$children}no_child{/if} {if $level>1&&$children}isOpen{/if}">
    <div class="self clearfix">
        <i class="lline"></i>
        {$child_count = count($children)}
        <span class="menu_action">
            <a href="{url('PowerTree/create',['parent_id'=>$self_id])}"><i class="fa fa-plus"></i>添加子节点</a>
            {if $child_count>1}<a href="{url('PowerTree/sort',['parent_id'=>$self_id])}"><i class="fa fa-sort"></i>排序子节点</a>{/if}            
            <a href="{url('PowerTree/modify',['id'=>$self_id])}"><i class="fa fa-edit"></i>编辑</a>
            <a href="{url('PowerTree/delete',['id'=>$self_id])}" class="item-action-delete"><i class="fa fa-close"></i>删除</a>
            {if powertree($self_id,'url')}
            <a href="{url(powertree($self_id,'url'))}"><i class="fa fa-eye"></i>访问</a>
            {/if}
        </span>
        <span class="menu_info clearfix">            
            <i class="fa  {if $children}{if $level==1}fa-plus-circle{else}fa-minus-circle{/if}{else}fa-minus-circle{/if}  fa-lg left fa-icon"></i>
            <span class="menu_title left">
                {if powertree($self_id,'icon')}<i class="fa {powertree($self_id,'icon')}"></i>{/if} 
                <a href="{url('PowerTree/modify',['id'=>$self_id])}">{powertree($self_id,'title')}</a>
            </span>
            <span class="menu_id left">〖ID：{$self_id}〗</span>  
            <span class="left en-font">〖控制器：{powertree($self_id,'controller')}〗</span>
            {if powertree($self_id,'action')}<span class="left en-font">〖方法：{powertree($self_id,'action')}〗</span> {/if}                 
            {if $child_count>0}<span class="menu_child_count left">〖子节点数：{$child_count}〗</span>{/if}
        </span>
    </div>
    {if $children}
    <div class="menu_children">
        {call tree data=$children level=$level+1}
    </div>
    {/if}
</div>
{/foreach}
{/function}

<div id="menu_tree">
    {call tree data=reset(powertree('threaded')) level=1}
</div>

{else}
<div style="text-align: center;padding-top: 50px;"><a href="{url('PowerTree/start')}" rel="start" class="layui-btn javascript">初始化权限节点</a>
    <p>首次使用，请先<strong>初始化权限节点</strong>；以避免手动添加大量节点数据。</p>
</div>
{/if}

{/block}
{block name=script}
<script>

function start(){
    var url = $(this).attr('href');
    layer.msg('处理中请稍后...',{ time:20, shade :[0.01, '#393D49']});
    HKUC.ajax_request.call(this,url,null,
    	{
    		'success':function(msg,data){
  		        layer.closeAll();
                layer.alert(msg, function(){
                    location.reload();
                });
                
    		},
    		'error':function(msg,data){
                  layer.closeAll();
                  layer.msg(msg)
    		}
    	}
    );
}

$('#menu_tree .self').click(function(){
    var parent = $(this).parent('.menu_level') ;
    $('#menu_tree').find('.isClick').removeClass('isClick');
    parent.addClass('isClick');
    if(parent.hasClass('no_child')) return false ;
    if(parent.hasClass('isOpen'))
        parent.removeClass('isOpen').children('.menu_children').hide().end().children('.self').find('.fa-icon').removeClass('fa-minus-circle').addClass('fa-plus-circle')
    else
        parent.addClass('isOpen').children('.menu_children').show().end().children('.self').find('.fa-icon').removeClass('fa-plus-circle').addClass('fa-minus-circle')
}).find('a').click(function(e){
    e.stopPropagation();
    if($(this).hasClass('item-action-delete')){
        var href  = $(this).attr('href') ;
        layer.confirm('该操作不可逆，请确认删除该栏目及其子栏目？',function(){
            layer.closeAll();
            location.href  = href; 
        })
        return false ;
    }
})

</script>

{/block}
